package model;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class StakeManager {
    // 用于存储stake
    private ConcurrentHashMap<Integer, BettingOffer> offers = new ConcurrentHashMap<>();

    /**
     * 更新投注
     * @param betOfferId 投注ID
     * @param customerId 用户ID
     * @param stake 投注金额
     */
    public void updateBettingOffer(int betOfferId, int customerId, int stake) {
        offers.compute(betOfferId, (id, offer) -> {
            if (offer == null) {
                offer = new BettingOffer(id);
            }
            offer.updateStake(customerId, stake);
            return offer;
        });
    }

    /**
     * 获取投注的top20
     * @param betOfferId 投注ID
     * @return top20的map
     */
    public Map<Integer, Integer> getTop20StakesForOffer(int betOfferId) {
        BettingOffer offer = offers.get(betOfferId);
        return offer != null ? offer.getTop20Stakes() : Collections.emptyMap();
    }
}